package ventanas;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaRegistro.java
 *
 * Created on 07-ago-2010, 16:42:43
 */
//import datosClient.*;
import java.awt.Color;

import logicaClient.*;
import javax.swing.JFrame;
import java.util.Calendar;


/**
 *
 * @author aiskel
 */
public class VentanaRegistro extends javax.swing.JFrame {

    /** Creates new form VentanaRegistro */
    public VentanaRegistro() {
        initComponents();
          this.VentanaPadre4 = null;
        //Comunicacion.inicializarEstructuras();
    }

    public VentanaRegistro(JFrame ventanaPadre4)
    {
        initComponents();
        this.VentanaPadre4 = ventanaPadre4;
    }

    public void setVentanaPadre2(JFrame VentanaPadre2) {
        this.VentanaPadre2 = VentanaPadre2;
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLNickName = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTFNombre = new javax.swing.JTextField();
        jTFApellido = new javax.swing.JTextField();
        jTFNickname = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jPFClave = new javax.swing.JPasswordField();
        buttonAceptar = new java.awt.Button();
        buttonCancelar = new java.awt.Button();
        jLabel1 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jLabel12 = new javax.swing.JLabel();
        jLError = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jCalendarCombo1 = new org.freixas.jcalendar.JCalendarCombo();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Registro en el Sistema");
        setName("VentanaRegistro"); // NOI18N

        jLabel2.setText("Nombre:");
        jLabel2.setName("EtiquetaNombre"); // NOI18N

        jLabel3.setText("Apellido:");
        jLabel3.setName("EtiquetaApellido"); // NOI18N

        jLabel4.setText("Fecha de Nacimiento");
        jLabel4.setName("EtiquetaFechaN"); // NOI18N

        jLNickName.setText("Nickname");
        jLNickName.setName("EtiquetaNickname"); // NOI18N

        jLabel6.setText("Clave");
        jLabel6.setName("EtiquetaClave"); // NOI18N

        jTFNickname.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTFNicknameActionPerformed(evt);
            }
        });

        jLabel7.setText("Avatar:");

        buttonAceptar.setLabel("Aceptar");
        buttonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAceptarActionPerformed(evt);
            }
        });

        buttonCancelar.setLabel("Cancelar");
        buttonCancelar.setName(""); // NOI18N
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });

        jLabel10.setText("  Masculino");

        jLabel11.setText("  Femenino");

        jRadioButton1.setText("jRadioButton1");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jRadioButton2.setText("jRadioButton1");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/fondos-lisa-simpsons-p.jpg"))); // NOI18N

        jLError.setForeground(new java.awt.Color(255, 0, 0));

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/Bart Simpsons.jpg"))); // NOI18N
        jLabel13.setText("jLabel5");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLNickName, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jCalendarCombo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jPFClave, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTFApellido, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                                    .addComponent(jTFNombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                                    .addComponent(jTFNickname, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(67, 67, 67)
                                .addComponent(jRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(107, 107, 107)
                                .addComponent(jRadioButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(buttonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel8)
                                            .addGap(121, 121, 121)
                                            .addComponent(jLabel1))))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(37, 37, 37)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel11)
                                            .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(buttonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(112, 112, 112)
                        .addComponent(jLError)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel8)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel7))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTFApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4)
                                    .addComponent(jCalendarCombo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(32, 32, 32)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTFNickname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLNickName))
                                .addGap(27, 27, 27)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jPFClave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel12)
                                        .addGap(18, 18, 18)
                                        .addComponent(jRadioButton1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel13)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jRadioButton2)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel10))))))
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(buttonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(97, 97, 97)
                .addComponent(jLError)
                .addContainerGap())
        );

        buttonCancelar.getAccessibleContext().setAccessibleName("Aceptar");

        getAccessibleContext().setAccessibleName(" Regitro en el Sistema");
        getAccessibleContext().setAccessibleDescription(" Regitro en el Sistema");

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-677)/2, (screenSize.height-391)/2, 677, 391);
    }// </editor-fold>//GEN-END:initComponents

    private void jTFNicknameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTFNicknameActionPerformed
    }//GEN-LAST:event_jTFNicknameActionPerformed

    private void buttonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAceptarActionPerformed
      
        boolean sta = false;

        int avatarID = 0;
        String avatarPATH = "";
        avatarID = VentanaRegistro.getIDavatar();
        avatarPATH = VentanaRegistro.getPATHavatar();
        //System.out.println("lalalalala    " + avatarPATH);

        String datos="";//Ingreso al sistema de usuarios no registrados

        int diaNac,mesNac,añoNac=0;
        String sDia = ""; String sMes = "";



   //---------------------------------------------------------------
        Calendar calendario = Calendar.getInstance();
        calendario.setTime(jCalendarCombo1.getDate());
        diaNac = calendario.get(Calendar.DAY_OF_MONTH);
        mesNac = calendario.get(Calendar.MONTH) + 1;

        /*if(diaNac < 10)
           sDia = "0";
        sDia += diaNac;
        if(mesNac < 10)
           sMes = "0";
        sMes += mesNac;*/
        fecha = diaNac + "/" + mesNac + "/" + calendario.get(Calendar.YEAR);

   //---------------------------------------------------------------
        System.out.println("\nFecha en boton Aceptar de ventana registro: "+fecha+"\n");

        datos = ComunicacionClient.obtenerDatosUsuario(jTFNombre, jTFApellido, fecha, jTFNickname, jPFClave, avatarID,avatarPATH);

        System.out.println("DATOSS EN ACEPTAR DE VENTANA REGISTRO...: "+datos);

        //System.out.println("Lo que me devuelve luego en comunicacion  "+ComunicacionJSockets.solicitarEnvioDatos(datos));
        retorno = ComunicacionJSockets.solicitarEnvioDatos(datos);
          if (retorno.compareTo("false")==0 || retorno.compareTo("FALSE")==0)
            {
               jLError.setText("nickname repetido");
               jLNickName.setForeground(Color.RED);
            }
            else
            {

                    //int dia2,mes2,año2=0;
                ComunicacionClient.IngresoDatosUsuario(jTFNickname.getText(), jPFClave.getText(), jTFNombre.getText(), jTFApellido.getText(),avatarID,avatarPATH);
                //dia2=2;mes2=6;año2=2010;/*HAY QUE ACOMODARLO CON LA FECHA ACTUAL!!!!*/

                //System.out.println("\nFecha en boton Aceptar de ventana registro: "+fecha+"\n");

                //System.out.println("\nFecha en boton Aceptar de ventana registro(¿actual?): "+jCalendarCombo1.getDate()+"\n");

                ComunicacionClient.getLosUsuarios().agregarFechaNac(diaNac, mesNac, añoNac);

                // ComunicacionClient.agregarDatosUsuario();
             //  ComunicacionClient.imprimirListaDeUsuarios();
               //System.out.println("miiiiiiraaaaaa " + objeto);
               //this.setVisible(false);
               this.dispose();
               VentanaUsuario ventanaUsuario = new VentanaUsuario();
               ventanaUsuario.setVisible(true);
            }


        /*String fechaNac="";

        datos.concat(":");
        datos.concat(jTFNickname.getText());
        datos.concat(":");
        datos.concat(jPFClave.getText());
        datos.concat(":");
        datos.concat(jTFNombre.getText());
        datos.concat(":");
        datos.concat(jTFApellido.getText());
        datos.concat(":");


        fechaNac.concat(jCBDia.toString());
        fechaNac.concat("/");
        fechaNac.concat(jCBMes.toString());
        fechaNac.concat("/");
        fechaNac.concat(jCBAño.toString());

        datos.concat(fechaNac);*/
   /*
        datos.concat(":");
        datos.concat(ID);

     */


/*
       sta = ComunicacionClient.obtenerDatosUsuario(jTFNombre, jTFApellido, jCBDia, jCBMes, jCBAño, jTFNickname, jPFClave);
      // sta = ComunicacionClient.verificarNick(objeto);
       System.out.println("el booleano salio en -->" + sta);
       if (sta==true)
       {
           jLError.setText("nickname repetido");
           jLNickName.setForeground(Color.RED);
       }
       else
       {
           //ComunicacionClient.aignarIconoUsuario(jRadioButton1, jRadioButton2);
           ComunicacionClient.agregarDatosUsuario();
         //  ComunicacionClient.imprimirListaDeUsuarios();
           //System.out.println("miiiiiiraaaaaa " + objeto);
        this.setVisible(false);
        VentanaJugada ventana = new VentanaJugada();
       ventana.setVisible(true);
        }

        //Sthis.setVisible(false);*/
    }//GEN-LAST:event_buttonAceptarActionPerformed

    private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
       VentanaPadre2.setVisible(true);
    }//GEN-LAST:event_buttonCancelarActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        // TODO add your handling code here:

                   /* jRadioButton1.setSelected(true);
                    jRadioButton2.setSelected(false);*/
        this.setVisible(false);
        VentanaAvataresFemeninos ventanaAvataresM = new VentanaAvataresFemeninos();
        ventanaAvataresM.setVisible(true);
        ventanaAvataresM.setVentanaPadre4(this);

    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
        /* jRadioButton2.setSelected(true);
         jRadioButton1.setSelected(false);*/
         this.setVisible(false);
         VentanaAvataresMasculinos ventanaAvataresF = new VentanaAvataresMasculinos();
        ventanaAvataresF.setVisible(true);
        ventanaAvataresF.setVentanaPadre4(this);
    }//GEN-LAST:event_jRadioButton2ActionPerformed


    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaRegistro().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button buttonAceptar;
    private java.awt.Button buttonCancelar;
    private org.freixas.jcalendar.JCalendarCombo jCalendarCombo1;
    private javax.swing.JLabel jLError;
    private javax.swing.JLabel jLNickName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPasswordField jPFClave;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JTextField jTFApellido;
    private javax.swing.JTextField jTFNickname;
    private javax.swing.JTextField jTFNombre;
    // End of variables declaration//GEN-END:variables

    private String fecha="";

    javax.swing.JFrame VentanaPadre4;
    private JFrame VentanaPadre2;
    private String retorno="";
    private static int IDavatar;
    private static String PATHavatar;



    public static int getIDavatar() {
        return IDavatar;
    }

    public static void setIDavatar(int IDavatar) {
        VentanaRegistro.IDavatar = IDavatar;
    }

    public static String getPATHavatar() {
        return PATHavatar;
    }

    public static void setPATHavatar(String PATHavatar) {
        VentanaRegistro.PATHavatar = PATHavatar;
    }




}
